// popup.js

document.getElementById("getElements").addEventListener("click", () => {
	const className = "aaaaa";//document.getElementById("className").value;
	if (className) 
	{
		chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
			chrome.tabs.sendMessage(tabs[0].id,
				{ action: "getElementsByClassName", className: className, openwindow: false },
				(response) => {
					const resultDiv = document.getElementById("result");
					if (response && response.success)
					{
						resultDiv.innerHTML = "该专栏共有文章数：" + response.count + "#" + response.alllinks.length;
					}
					else
					{
						resultDiv.innerHTML = "获取失败";
					}
				});
		});
	} 
	else 
	{
		alert("Please enter a class name.");
	}
});


document.getElementById("OpenAllLink").addEventListener("click", () => {
	const className = "aaaaa";//document.getElementById("className").value;
	if (className) 
	{
		chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
			chrome.tabs.sendMessage(tabs[0].id,
				{ action: "getElementsByClassName", className: className, openwindow: true},
				(response) => {
					const resultDiv = document.getElementById("result");
					if (response && response.success)
					{
						resultDiv.innerHTML = "该专栏共有文章数：" + response.count + "#" + response.alllinks.length;
					}
					else
					{
						resultDiv.innerHTML = "获取失败";
					}
				});
		});
	} 
	else 
	{
		alert("Please enter a class name.");
	}
});
